<template>
	<view class="page">
		<u--form
			labelPosition="top"
			:model="basicForm"
			ref="form1"
			labelWidth="auto"
			:labelStyle="{
				fontSize: '14px',
				color: '#B2B2B2',
				lineHight: '20px'
			}"
		>
			<view class="basic-style">
				<view class="basic-title basic-border">基础信息</view>
				<u-form-item
					label="单据编号"
					prop="billNo"
					:borderBottom="false"
				>
					<u--input
						disabled
						placeholder="请输入单据编号"
						v-model="basicForm.billNo"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="填表时间"
					prop="createTime"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.createTime"
						disabled
						placeholder="请选择时间"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="经办人"
					prop="proposer_dictText"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.proposer_dictText"
						disabled
						placeholder="请选择经办人"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="经办部门"
					prop="proposerDeptId_dictText"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.proposerDeptId_dictText"
						disabled
						placeholder="请选择经办部门"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
			</view>
			<view class="basic-style">
				<view class="basic-title basic-border">汇款信息</view>
				
				<u-form-item
					label="汇款单位名称"
					prop="remittanceUnit_dictText"
					:borderBottom="false"
					required
				>
					<u--input
						disabled
						placeholder="请选择汇款单位名称"
						v-model="basicForm.remittanceUnit_dictText"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="汇款日期"
					prop="remittanceDate"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.remittanceDate"
						disabled
						placeholder="请选择汇款日期"
						border="surround"
						suffixIcon="calendar-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="汇款金额(元)"
					prop="remittanceAmount"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.remittanceAmount"
						placeholder="请输入汇款金额"
						border="surround"
						disabled
					></u--input>
				</u-form-item>
				<u-form-item
					label="支付方式"
					prop="payMode_dictText"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.payMode_dictText"
						disabled
						placeholder="请选择支付方式"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="收款单位名称"
					prop="payeeUnit_dictText"
					:borderBottom="false"
					required
				>
					<u--input
						v-model="basicForm.payeeUnit_dictText"
						disabled
						placeholder="请选择收款单位名称"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="收款银行"
					prop="bankName"
					:borderBottom="false"
					required
					v-if="basicForm.payMode==1"
				>
					<u--input
						v-model="basicForm.bankName"
						disabled
						placeholder="请输入收款银行"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="收款账户"
					prop="payeeAccountNo"
					:borderBottom="false"
					required
					v-if="basicForm.payMode == 1"
				>
					<u--input
						v-model="basicForm.payeeAccountNo"
						disabled
						placeholder="请输入收款账户"
						border="surround"
					></u--input>
				</u-form-item>
				<u-form-item
					label="备注"
					prop="remark"
					:borderBottom="false"
				>
					<u--textarea v-model="basicForm.remark" disabled confirmType="done" placeholder="请输入备注" ></u--textarea>
				</u-form-item>
			</view>
			<view class="basic-style">
				<view class="basic-title basic-border">认领信息</view>
				
				<u-form-item
					label="认领人"
					prop="employeeId_dictText"
					:borderBottom="false"
				>
					<u--input
						v-model="basicForm.employeeId_dictText"
						disabled
						placeholder="请选择人员"
						border="surround"
						suffixIcon="arrow-down-fill"
						:suffixIconStyle="{color: '#B2B2B2'}"
					></u--input>
				</u-form-item>
				<u-form-item
					label="是否为保证金"
					prop="isDeposit"
					:borderBottom="false"
					required
				>
					<h-dict-radio disabled @change="onIsDepositChange" v-model="basicForm.isDeposit" dictName="is_deposit"></h-dict-radio>
				</u-form-item>
				<block v-if="basicForm.isDeposit == '1'">
					<u-form-item
						label="关联保证金申请单"
						prop="depositBillId"
						:borderBottom="false"
						required
					>
						<!-- payeeUnit 需要通过收款单位查询汇款单位 -->
						<h-select-finance-deposit-bill-input
							v-model="basicForm.depositBillId"
							:applicant="basicForm.payeeUnit"
							objectField="basicForm.depositBillId"
							style="width: 100%;"
							border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
							@detail="getdepositBill"
						>
						</h-select-finance-deposit-bill-input>
					</u-form-item>
					<u-form-item
						label="保证金类型"
						prop="feeCategory_dictText"
						:borderBottom="false"
					>
						<u--input
							v-model="basicForm.feeCategory_dictText"
							disabled
							placeholder="请选择保证金类型"
							border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
						></u--input>
					</u-form-item>
					<u-form-item
						label="保证金金额(元)"
						prop="depositRemittanceAmount"
						:borderBottom="false"
					>
						<u--input
							v-model="basicForm.depositRemittanceAmount"
							disabled
							placeholder="请输入保证金金额"
							border="surround"
						></u--input>
					</u-form-item>
					<u-form-item
						label="利息金额(元)"
						prop="interestAmount"
						:borderBottom="false"
						required
					>
						<u--input
							v-model="basicForm.interestAmount"
							placeholder="请输入利息金额"
							border="surround"
							type="number"
							@change="onInterestAmountChange"
						></u--input>
					</u-form-item>
				</block>
				<block v-if="basicForm.isDeposit=='0'">
					
					<view class="inforamtion" style="display: flex;" v-for="(item, index) in getManagerPlanList" :key="index">
						<view >
							<view class="option" style="width: 520rpx;">
								<view class="lf">项目名称</view>
								<view class="rl">{{ item.projectId_dictText }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">项目编号</view>
								<view class="rl">{{ item.projectCode }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">项目承接人</view>
								<view class="rl">{{ item.projectUndertaker_dictText }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">业绩归属年度</view>
								<h-dictCode class="rl" :value="item.projectYear" dictName="yjgsnd"></h-dictCode>
							</view>
							<!-- <view class="option" style="width: 520rpx;">
								<view class="lf">费用所属年度</view>
								<h-dictCode class="rl" :value="item.teamYear" dictName="tdnd_type"></h-dictCode>
							</view> -->
							<view class="option" style="width: 520rpx;">
								<view class="lf">经营团队</view>
								<view class="rl">{{ item.busiTeamId_dictText }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">项目合同</view>
								<view class="rl">{{ item.contractNo_dictText }}</view>
							</view>
							<!-- <view class="option" style="width: 520rpx;">
								<view class="lf">项目进度</view>
								<view class="rl">{{ item.projectPlan_dictText }}</view>
							</view> -->
							<view class="option" style="width: 520rpx;">
								<view class="lf">合同款项</view>
								<view class="rl">{{ item.contractMoneyItemId_dictText }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">应收款(元)</view>
								<view class="rl">{{ item.receivables }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">已收款(元)</view>
								<view class="rl">{{ item.collectedMoney }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">累计扣款(元)</view>
								<view class="rl">{{ item.totalDeductMoney }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">本次收款(元)</view>
								<view class="rl">{{ item.amount }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">本次扣款(元)</view>
								<view class="rl">{{ item.deductMoney }}</view>
							</view>
							<view class="option" style="width: 520rpx;">
								<view class="lf">未回款(元)</view>
								<view class="rl">{{ item.unreturnedMoney }}</view>
							</view>
						</view>
						<view style="flex: 1; display: flex; align-items: center; justify-content: flex-end;">
							<u-icon name="edit-pen-fill" color="#2979ff" size="20" @click="onManagerTrusteeEdit(item, index)"></u-icon>
							<u-line  direction="col" length="20" margin="0 10rpx"></u-line>
							<u-icon  name="trash-fill" color="#2979ff" size="20"  @click="onManagerTrusteeDelete(item, index)"></u-icon>
						</view>
					</view>
					<view  style="margin: 20rpx 0rpx 0rpx;">
						<u-button text="新增" type="primary" @click="onManagerTrusteeAdd"></u-button>
					</view>
				</block>
			</view>
		</u--form>
		
		<!-- 附件 -->
		<view class="basic-style">
			<view class="basic-title basic-border">附件信息</view>
			<!-- <file-list :fileList="basicForm.attachment" style="padding-top:16rpx"></file-list> -->
			<view class="" style="width: 100%;">
				<h-upload-file v-model="basicForm.attachments" :isIcon="false"></h-upload-file>
				<file-list v-if="basicForm.attachments" v-model="basicForm.attachments" :isDelete="true"></file-list>
			</view>
		</view>
		
		<!-- <view class="" style="padding: 20rpx; display: flex;">
			<u-button style="margin-right:20rpx;" type="primary" text="提交" @click="onSubmit"></u-button>
			<u-button type="primary" text="审核" @click="onAudit"></u-button>
		</view> -->
		<view class="space-x-1 px-1 btn_position">
			<backButton  @onSubmit="onSubmit" :nodeObj="nodeObj" :model="model" :resultObj="resultObj"></backButton>
		</view>
		<view style="height: 100rpx;"></view>
		
		<!-- 认领信息弹窗 -->
		<u-popup :show="showManagerTrusteePopup" @close="closeManagerTrusteePopup" :round="10" :customStyle="{maxHeight: '600px', padding:'20rpx 0'}">
			<view style="background-color: #ffffff; border-radius: 10px; padding: 20rpx;overflow: auto;">
				<u--form
					labelPosition="top"
					:model="managerTrusteeForm"
					ref="form1"
					labelWidth="auto"
					:labelStyle="{
						fontSize: '14px',
						color: '#B2B2B2',
						lineHight: '20px'
					}"
				>
					<u-form-item
						label="项目名称"
						prop="projectId"
						:borderBottom="false"
						required
					>
						<h-select-project-input
							projectStatus="2"
							:signUnit="basicForm.payeeUnit"
							v-model="managerTrusteeForm.projectId"
							style="width: 100%;"
							placeholder="请选择项目名称"
							objectField="managerTrusteeForm.projectId"
							border="surround"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
							@detail="selectProject"
						>
						</h-select-project-input>
					</u-form-item>
					<u-form-item label="项目编号" prop="projectCode">
						<u--input disabled placeholder="请输入项目编号" v-model="managerTrusteeForm.projectCode"></u--input>
					</u-form-item>
					<u-form-item
						label="项目承接人"
						prop="projectUndertaker_dictText"
						:borderBottom="false"
					>
						<u--input
							v-model="managerTrusteeForm.projectUndertaker_dictText"
							disabled
							placeholder="请输入项目承接人"
							border="surround"
						></u--input>
					</u-form-item>
					<u-form-item
						label="业绩归属年度"
						prop="projectYear"
						:borderBottom="false"
					>
						<h-dict-select
							style="width: 100%" 
							v-model="managerTrusteeForm.projectYear" 
							disabled
							placeholder="请选择业绩归属年度" 
							dictName="yjgsnd" 
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
						></h-dict-select>
					</u-form-item>
					<!-- <u-form-item
						label="费用所属年度"
						prop="teamYear"
						:borderBottom="false"
					>
						<h-dict-select
							style="width: 100%" 
							v-model="managerTrusteeForm.teamYear" 
							placeholder="请选择业绩费用所属年度"
							dictName="tdnd_type" 
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
						></h-dict-select>
					</u-form-item> -->
					<u-form-item
						label="经营团队"
						prop="busiTeamId"
						:borderBottom="false"
					>
						<h-select-team-input
							style="width: 100%;"
							disabled
							v-model="managerTrusteeForm.busiTeamId"
							objectField="managerTrusteeForm.busiTeamId"
							placeholder="请选择经营团队"
							border="surround"
							:tdlx="3"
						></h-select-team-input>
					</u-form-item>
					<u-form-item
						label="项目合同"
						prop="contractNo"
						:borderBottom="false"
						required
					>
						<h-select-contract-manager-input
							v-model="managerTrusteeForm.contractNo"
							objectField="managerTrusteeForm.contractNo"
							:projectId="managerTrusteeForm.projectId"
							placeholder="请选择项目合同"
							border="surround"
							style="width: 100%;"
							htlx="1"
							status="2,3,7"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
							@detail="getContractInfo"
							@onErr="getContractInfoErr"
						>
						</h-select-contract-manager-input>
					</u-form-item>
					<!-- <u-form-item
						label="项目进度"
						prop="projectPlan_dictText"
						:borderBottom="false"
						required
					>
						<u--input
							v-model="managerTrusteeForm.projectPlan_dictText" 
							placeholder="请选择项目进度"
							border="surround"
							disabled
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
						></u--input>
					</u-form-item> -->
					<u-form-item
						label="合同款项"
						prop="contractMoneyItemId"
						:borderBottom="false"
						required
					>
						<h-select-checkoutlist-input
							v-model="managerTrusteeForm.contractMoneyItemId"
							objectField="managerTrusteeForm.contractMoneyItemId"
							:contractId="managerTrusteeForm.contractNo"
							placeholder="请选择合同款项"
							border="surround"
							style="width: 100%;"
							suffixIcon="arrow-down-fill"
							:suffixIconStyle="{color: '#B2B2B2'}"
							@detail="getCheckoutInfo"
							@onErr="getCheckoutInfoErr"
						></h-select-checkoutlist-input>
					</u-form-item>
					<u-form-item
						label="应收款(元)"
						prop="receivables"
						:borderBottom="false"
					>
						<u--input
							v-model="managerTrusteeForm.receivables"
							placeholder="请输入应收款"
							border="surround"
							disabled
							type="number"
							@change="inputAmount"
						></u--input>
					</u-form-item>
					<u-form-item
						label="已收款(元)"
						prop="collectedMoney"
						:borderBottom="false"
					>
						<u--input
							v-model="managerTrusteeForm.collectedMoney"
							placeholder="请输入已收款"
							border="surround"
							type="number"
							disabled
							@change="inputAmount"
						></u--input>
					</u-form-item>
					<u-form-item
						label="累计扣款(元)"
						prop="totalDeductMoney"
						:borderBottom="false"
					>
						<u--input
							v-model="managerTrusteeForm.totalDeductMoney"
							placeholder="请输入累计扣款"
							disabled
							border="surround"
							type="number"
							@change="inputAmount"
						></u--input>
					</u-form-item>
					<u-form-item
						label="本次收款(元)"
						prop="amount"
						:borderBottom="false"
						required
					>
						<u--input
							v-model="managerTrusteeForm.amount"
							placeholder="请输入本次收款"
							border="surround"
							type="number"
							@change="inputAmount"
						></u--input>
					</u-form-item>
					<u-form-item
						label="本次扣款(元)"
						prop="deductMoney"
						:borderBottom="false"
						required
					>
						<u--input
							v-model="managerTrusteeForm.deductMoney"
							placeholder="请输入本次扣款"
							border="surround"
							type="number"
							@change="inputAmount"
						></u--input>
					</u-form-item>
					<u-form-item
						label="未回款(元)"
						prop="unreturnedMoney"
						:borderBottom="false"
					>
						<u--input
							v-model="managerTrusteeForm.unreturnedMoney"
							placeholder="请输入未回款"
							border="surround"
							type="number"
							disabled
						></u--input>
					</u-form-item>
				</u--form>
				<view style="padding-bottom:20rpx;">
					<u-button text="确定" type="primary" @click="onConfirmManagerTrusteePopup"></u-button>
				</view>
			</view>
		</u-popup>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
import fileList from './components/fileList.vue'
import backButton from '@/components/backButton.vue'
import Decimal from 'decimal.js'
import {
	queryByIdcollectMoney, // 根据id查询财务收款申请单审批流程
	editCollectMoney ,// 编辑财务收款申请单审批流程
	queryByIdBorrowMoneyChild, // 认领信息详情,
	getProcessTaskTransInfo // 流程流转
} from '@/api/index.js'
import {
	BASE_URL
} from '@/utils/baseUrl.js'
import { convertCurrency } from '@/utils/MoneyConvert' // 金额大写转换
import {
		mapState,
	} from 'vuex';
export default {
	components: {
		fileList,
		backButton
	},
	data() {
		return {
			isRefresh: false, // 获取项目信息时是否清空数据 false - 不清空
			isCheckoutInfoRefresh: false, // 获取合同款项信息时是否清空数据 false - 不清空
			isContractNoInfoRefresh: false, // 获取合同信息时是否清空数据 false - 不清空
			isSubmit: false,
			basicForm: {},
			nodeObj: {},
			tabvalue:'',
			id: '', // 详情id值
			model: {},
			getManagerPlanList: [], // 认领信息
			showManagerTrusteePopup: false, // 认领信息弹窗
			clickManagerTrusteePopup: '', // 点击编辑还是新增
			managerTrusteeForm: {
				projectId: '',
				projectUndertaker: '',
				projectUndertaker_dictText: '',
				projectYear: '',
				busiTeamId: '',
				busiTeamId_dictText: '',
				contractNo: '',
				contractNo_dictText: '',
				projectPlan: '',
				projectPlan_dictText: '',
				contractMoneyItemId: '',
				receivables: '',
				collectedMoney: '',
				totalDeductMoney: '',
				amount: '',
				deductMoney: '',
				unreturnedMoney: '',
			}, // 对象
			managerTrusteeIndex: 0, // 点击编辑的index值
			userInformation: '', // 用户信息
			resultObj: {},
			isChecked: false
		};
	},
	onLoad(options) {
		// 获取用户信息
		this.userInformation = this.userInfo()
		this.model = JSON.parse(decodeURIComponent(options.item))
		var that = this
		// #ifdef APP-NVUE
			var eventChannel = this.$scope.eventChannel; // 兼容APP-NVUE
		// #endif
		// #ifndef APP-NVUE
			var eventChannel = this.getOpenerEventChannel();
		// #endif
		// 监听sendMessage事件，获取上一页面通过eventChannel传送到当前页面的数据
		eventChannel.on('sendMessage', function(data) {
			that.tabvalue = data.tabvalue
			that.nodeObj = JSON.parse(decodeURIComponent(data.nodeObj))
			that.id = that.nodeObj.dataId
			that.loadData(that.nodeObj.dataId)
			that.getProcessTaskTrans(that.model.id)
		})
		
		
	},
	methods: {
		...mapState(['userInfo']),
		loadData(id){
			queryByIdcollectMoney({ id }).then(res => {
				if(res.success){
					this.basicForm = res.result
					this.getQueryByIdBorrowMoneyId(res.result.id)
					this.$set(this.basicForm,'employeeId', this.userInformation.empId)
					this.$set(this.basicForm,'employeeId_dictText', this.userInformation.realname)
					
					
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		// 查询流程流转信息 -- 获取下一节点信息
		getProcessTaskTrans(taskId){
			getProcessTaskTransInfo({ taskId }).then(res => {
				if(res.success){
					this.resultObj = res.result
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			}).catch(err => {
				console.log(err);
			})
		},
		
		// 点击切换是否为保证金
		onIsDepositChange (item) {
			if (item == 1) {
				this.getManagerPlanList = []
			} else {
				this.basicForm.depositBillId = ''
				this.basicForm.feeCategory_dictText = ''
				this.basicForm.feeCategory = ''
				this.basicForm.depositRemittanceAmount = ''
				this.basicForm.interestAmount = ''
			}
		},
		
		// 获取认领信息详情
		getQueryByIdBorrowMoneyId (id) {
			queryByIdBorrowMoneyChild({ billId: id }).then(res => {
				if(res.success){
					this.getManagerPlanList = res.result || []
					this.isChecked = this.getManagerPlanList&&this.getManagerPlanList.length==1
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		//输入金额
		inputAmount(arg){
			let unreturnedMoney = (this.managerTrusteeForm.receivables - this.managerTrusteeForm.collectedMoney - this.managerTrusteeForm.amount - this.managerTrusteeForm.deductMoney - this.managerTrusteeForm.totalDeductMoney).toFixed(2);
			if((!!this.managerTrusteeForm.receivables || this.managerTrusteeForm.receivables==0) && (!!this.managerTrusteeForm.collectedMoney || this.managerTrusteeForm.collectedMoney==0) && (!!this.managerTrusteeForm.amount || this.managerTrusteeForm.amount==0)
			&& (!!this.managerTrusteeForm.totalDeductMoney || this.managerTrusteeForm.totalDeductMoney==0) && (!!this.managerTrusteeForm.deductMoney || this.managerTrusteeForm.deductMoney==0)){
				if (unreturnedMoney == -0.00) {
						unreturnedMoney = 0.00;
					}
				this.$set(this.managerTrusteeForm,'unreturnedMoney',unreturnedMoney);
			}
		},
		
		// 获取合同报错
		getContractInfoErr () {
			uni.showToast({
				title: '请先选择项目',
				icon: 'none'
			})
		},
		
		//获取项目信息
		selectProject(data){
			this.$set(this.managerTrusteeForm, 'projectCode', data?.finalNo || '')
			if(data){
				this.$set(this.managerTrusteeForm, 'projectId_dictText', data.projectName)
				this.$set(this.managerTrusteeForm, 'projectUndertaker', data.undertaker) // 项目承接人id
				this.$set(this.managerTrusteeForm, 'projectUndertaker_dictText', data.undertaker_dictText) // 项目承接人名称
				this.$set(this.managerTrusteeForm, 'projectYear', data.year)
				this.$set(this.managerTrusteeForm, 'busiTeamId', data.teamName)
				this.$set(this.managerTrusteeForm, 'busiTeamId_dictText', data.teamName_dictText)
				if (this.clickManagerTrusteePopup == 'edit') {
					if (this.isRefresh) {
						this.$set(this.managerTrusteeForm,'projectPlan',null);
						this.$set(this.managerTrusteeForm,'projectPlan_dictText','');
						this.$set(this.managerTrusteeForm,'contractNo',null); // 项目合同
						this.$set(this.managerTrusteeForm,'contractNo_dictText',null); // 项目合同名称
						this.$set(this.managerTrusteeForm,'contractMoneyItemId',null);
						this.$set(this.managerTrusteeForm,'collectedMoney',0);
						this.$set(this.managerTrusteeForm,'receivables',0);
						this.$set(this.managerTrusteeForm,'totalDeductMoney',0);
						this.$set(this.managerTrusteeForm,'amount','');
						this.$set(this.managerTrusteeForm,'deductMoney','');
						this.$set(this.managerTrusteeForm,'unreturnedMoney','');
						
					} else {
						this.isRefresh = true
					}
				} else {
					this.$set(this.managerTrusteeForm,'projectPlan',null);
					this.$set(this.managerTrusteeForm,'projectPlan_dictText','');
					this.$set(this.managerTrusteeForm,'contractNo',null); // 项目合同
					this.$set(this.managerTrusteeForm,'contractNo_dictText',null); // 项目合同名称
					this.$set(this.managerTrusteeForm,'contractMoneyItemId',null);
					this.$set(this.managerTrusteeForm,'collectedMoney',0);
					this.$set(this.managerTrusteeForm,'receivables',0);
					this.$set(this.managerTrusteeForm,'totalDeductMoney',0);
					this.$set(this.managerTrusteeForm,'amount','');
					this.$set(this.managerTrusteeForm,'deductMoney','');
					this.$set(this.managerTrusteeForm,'unreturnedMoney','');
				}
				
				
			}
		},
		// 关联保证金回显
		getdepositBill(data){
			if(data){
				this.$set(this.basicForm, 'depositRemittanceAmount', data.remittanceAmount);
				this.$set(this.basicForm, 'feeCategory', data.feeCategory);
				this.$set(this.basicForm, 'feeCategory_dictText', data.feeCategory_dictText);
			}
		},
		
		//获取项目合同信息
		getContractInfo(data){
			if(data){
				this.$set(this.managerTrusteeForm, 'contractNo_dictText', data.htmc); // 项目合同名称
				this.$set(this.managerTrusteeForm, 'projectPlan', data.contractNodeId);
				this.$set(this.managerTrusteeForm, 'projectPlan_dictText', data.contractNodeId_dictText);
				
				
				if (this.clickManagerTrusteePopup == 'edit') {
					if (this.isContractNoInfoRefresh) {
						this.$set(this.managerTrusteeForm,'contractMoneyItemId', ''); // 合同款项
						this.$set(this.managerTrusteeForm,'contractMoneyItemId_dictText', ''); // 合同款项
						this.$set(this.managerTrusteeForm,'receivables','');
						this.$set(this.managerTrusteeForm,'collectedMoney','');
						this.$set(this.managerTrusteeForm,'totalDeductMoney','');
						this.$set(this.managerTrusteeForm,'amount','');
						this.$set(this.managerTrusteeForm,'deductMoney','');
						this.$set(this.managerTrusteeForm,'unreturnedMoney','');
						
					} else {
						this.isContractNoInfoRefresh = true
					}
				} else {
					this.$set(this.managerTrusteeForm,'contractMoneyItemId', ''); // 合同款项
					this.$set(this.managerTrusteeForm,'contractMoneyItemId_dictText', ''); // 合同款项
					this.$set(this.managerTrusteeForm,'receivables','');
					this.$set(this.managerTrusteeForm,'collectedMoney','');
					this.$set(this.managerTrusteeForm,'totalDeductMoney','');
					this.$set(this.managerTrusteeForm,'amount','');
					this.$set(this.managerTrusteeForm,'deductMoney','');
					this.$set(this.managerTrusteeForm,'unreturnedMoney','');
				}
			}
		},
		
		// 合同款项详情
		getCheckoutInfo(data){
			if(data){
				 this.$set(this.managerTrusteeForm,'contractMoneyItemId_dictText',data.nodeName);
				 this.$set(this.managerTrusteeForm,'receivables',data.paymentMoney);
				 this.$set(this.managerTrusteeForm,'collectedMoney',data.realCollectionPaymentMoney);
				 this.$set(this.managerTrusteeForm,'totalDeductMoney',data.deductMoney);
				 
				 
				 if (this.clickManagerTrusteePopup == 'edit') {
				 	if (this.isCheckoutInfoRefresh) {
				 		this.$set(this.managerTrusteeForm,'amount','');
				 		this.$set(this.managerTrusteeForm,'deductMoney','');
				 		this.$set(this.managerTrusteeForm,'unreturnedMoney','');
				 		
				 	} else {
						this.isCheckoutInfoRefresh = true
					}
				 } else {
				 	this.$set(this.managerTrusteeForm,'amount','');
				 	this.$set(this.managerTrusteeForm,'deductMoney','');
				 	this.$set(this.managerTrusteeForm,'unreturnedMoney','');
				 }
				 
			}
		},
		
		// 获取合同款项报错
		getCheckoutInfoErr () {
			uni.showToast({
				title: '请先选择合同',
				icon:'none'
			})
		},
		
		// 点击新增子表弹窗
		onManagerTrusteeAdd () {
			this.managerTrusteeForm = {
				projectId: '',
				projectUndertaker: '',
				projectYear: '',
				busiTeamId: '',
				contractNo: '',
				projectPlan: '',
				projectPlan_dictText: '',
				contractMoneyItemId: '',
				receivables: '',
				collectedMoney: '',
				totalDeductMoney: '',
				amount: '',
				deductMoney: '',
				unreturnedMoney: '',
			} // 清空数据
			this.clickManagerTrusteePopup = 'add'
			this.showManagerTrusteePopup = true
		},
		// 点击编辑子表弹窗
		onManagerTrusteeEdit (item, index) {
			this.isRefresh = false
			this.isCheckoutInfoRefresh = false
			this.isContractNoInfoRefresh = false
			this.managerTrusteeForm.projectId = item.projectId
			this.managerTrusteeForm.projectUndertaker = item.projectUndertaker
			this.managerTrusteeForm.projectYear = item.projectYear
			this.managerTrusteeForm.busiTeamId = item.remark
			this.managerTrusteeForm.contractNo = item.contractNo
			this.managerTrusteeForm.projectPlan = item.projectPlan
			this.managerTrusteeForm.projectPlan_dictText = item.projectPlan_dictText
			this.managerTrusteeForm.contractMoneyItemId = item.contractMoneyItemId
			this.managerTrusteeForm.receivables = item.receivables
			this.managerTrusteeForm.collectedMoney = item.collectedMoney
			this.managerTrusteeForm.totalDeductMoney = item.totalDeductMoney
			this.managerTrusteeForm.amount = item.amount
			this.managerTrusteeForm.deductMoney = item.deductMoney
			this.managerTrusteeForm.unreturnedMoney = item.unreturnedMoney
			this.managerTrusteeIndex = index
			this.clickManagerTrusteePopup = 'edit'
			this.showManagerTrusteePopup = true
			
		},
		// 点击删除子表弹窗
		onManagerTrusteeDelete (item, index) {
			let _this = this
			uni.showModal({
				title: '确定删除',
				content: '确定删除此信息？',
				success (res) {
						if (res.confirm) {
							_this.getManagerPlanList.splice(index, 1)
						} else if (res.cancel) {
							// 用户点击取消
						}
					}
				
			})
		},
		showMessage(message){
			// this.$refs.uToast.show({
			// 	type: 'error',
			// 	icon: 'none',
			// 	message
			// })
			uni.showToast({
				title: message,
				icon: 'none'
			})
		},
		// 子表确定按钮
		onConfirmManagerTrusteePopup () {
			if(!this.managerTrusteeForm.projectId){
				this.showMessage('请选择项目名称')
				return
			}
			if(!this.managerTrusteeForm.contractNo){
				this.showMessage('请选择项目合同')
				return
			}
			// if(!this.managerTrusteeForm.projectPlan){
			// 	this.showMessage('请选择项目进度')
			// 	return
			// }
			if(!this.managerTrusteeForm.contractMoneyItemId){
				this.showMessage('请选择合同款项')
				return
			}
			if(!this.managerTrusteeForm.amount){
				this.showMessage('请输入本次收款')
				return
			}
			if(this.managerTrusteeForm.deductMoney === '' || this.managerTrusteeForm.deductMoney === null || this.managerTrusteeForm.deductMoney === undefined){
				this.showMessage('请输入本次扣款')
				return
			}
			// var idPar = parseInt(Math.random() * 1000000000000);
			if (this.clickManagerTrusteePopup == 'edit') {
				this.getManagerPlanList[this.managerTrusteeIndex] = this.managerTrusteeForm
			} else {
				this.managerTrusteeForm.billId = this.id
				this.getManagerPlanList.push(this.managerTrusteeForm)
				
			}
			this.showManagerTrusteePopup = false
			this.isRefresh = false
			this.isCheckoutInfoRefresh = false
			this.isContractNoInfoRefresh = false
			this.managerTrusteeForm = {
				projectId: '',
				projectUndertaker: '',
				projectYear: '',
				busiTeamId: '',
				contractNo: '',
				projectPlan: '',
				projectPlan_dictText: '',
				contractMoneyItemId: '',
				receivables: '',
				collectedMoney: '',
				totalDeductMoney: '',
				amount: '',
				deductMoney: '',
				unreturnedMoney: '',
			}
		},
		
		// 关闭子表弹窗
		closeManagerTrusteePopup () {
			this.isRefresh = false
			this.isCheckoutInfoRefresh = false
			this.isContractNoInfoRefresh = false
			this.showManagerTrusteePopup = false
		},
		
		// 利息金额
		onInterestAmountChange (value) {
			var _this = this
			var reg = /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/
			if (!reg.test(value)) {
				uni.showToast({
					title: '请输入正确的利息金额！',
					icon: 'none'
				})
			}
		},
		
		// 点击提交
		onSubmit () {
			var _this = this
			if(this.basicForm.isDeposit == '1'){
				this.basicForm.itemList = []
				// 是否有关联保证金申请单
				if (!this.basicForm.depositBillId) {
					uni.showToast({
						title: '请选择关联保证金申请单！',
						icon:'none'
					})
				  return false
				}
				// 是否有关联利息金额
				if (!this.basicForm.interestAmount) {
					uni.showToast({
						title: '请输入利息金额！',
						icon:'none'
					})
					return false
				}
				var reg = /^(([1-9][0-9]*|0)|([0]\.\d{0,2}|[1-9][0-9]*\.\d{0,2}))$/
				if (!reg.test(this.basicForm.interestAmount)) {
					uni.showToast({
						title: '请输入正确的利息金额！',
						icon: 'none'
					})
					return false
				}
			} else {
				if (this.getManagerPlanList == null || this.getManagerPlanList.length == 0) {
					uni.showToast({
						title: '请填写认领信息表格！',
						icon:'none'
					})
					return false;
				}
				if(this.isChecked){
					// 判断收款款项有一个没有填写数据时
					var itemLength = this.getManagerPlanList.filter(value => !value.contractMoneyItemId).length
					if (this.getManagerPlanList.length>0&&itemLength>0) {
						uni.showToast({
							title: '请完善认领信息中的数据！',
							icon:'none'
						})
						return false;
					}
				}
				
				if (this.getManagerPlanList && this.getManagerPlanList.length) {
					let itemList=this.getManagerPlanList;
					
					if(itemList.length>1){
						for (var i = 0; i < itemList.length - 1; i++) {
							for (var j = i + 1; j < itemList.length; j++) {
								if (itemList[i].contractMoneyItemId === itemList[j].contractMoneyItemId ) {
									uni.showToast({
										title: '请确保认领信息中不存在相同的合同款项！',
										icon: 'none'
									})
									return false;
								}
							}
						}
					}
					if(itemList.length>0){
						let amount = new Decimal(0);
						itemList.forEach(element => {
							amount = amount.add(Number(element.amount))
						});
						amount = amount.toNumber().toFixed(2)
						if(this.basicForm.remittanceAmount!=amount){
							uni.showToast({
								title: '汇款金额不等于收款金额总和！',
								icon: 'none'
							})
							return false;
						}
					}
					
					this.basicForm.itemList = uni.$u.deepClone(this.getManagerPlanList)
				} else {
					this.basicForm.itemList = []
				}
				
			}
			editCollectMoney(this.basicForm).then(res => {
				if (res.success) {
					// uni.showToast({
					// 	title: '提交成功!',
					// 	icon: 'none'
					// })
					this.isSubmit = true
					
					this.$refs.uToast.show({
						message: '提交成功',
						type: 'success',
						complete () {
							_this.onAudit()
						}
					})
				} else {
					this.$refs.uToast.show({
						message: res.message,
						type: 'error'
					})
				}
			})
		},
		
		onAudit() {
			if (!this.isSubmit) {
				uni.showToast({
					title: '请完善表单后审核',
					icon: 'none'
				})
				return false
			}
			var that = this
			uni.navigateTo({
				url: '/pages/synergy/collectMoneyApplicationBill'+`?item=${encodeURIComponent(JSON.stringify(this.model).replace(/%/g, '%25'))}`,
				events: {
					// 为指定事件添加一个监听器，获取被打开页面传送到当前页面的数据
					// acceptDataFromOpenedPage: function(data) {
					// 	console.log(data);
					// }
				},
				success: function(data) {
					// 通过eventChannel向被打开页面传送数据
					var params = {
						nodeObj: encodeURIComponent(JSON.stringify(that.nodeObj).replace(/%/g, '%25')),
						tabvalue: that.tabvalue
					}
					data.eventChannel.emit('sendMessage', params)
				},
				fail: function(err) {
					this.$refs.uToast.show({
						message: '请联系管理员配置',
						type: 'error'
					})
				}
			})
		}
	}
};
</script>

<style lang="scss" scoped>
@import url("@/assets/inputStyle.scss");
.basic-padding{
	padding-top: 16rpx;
}

// 评测信息
.info-title{
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #171717;
	line-height: 40rpx;
	padding-bottom: 16rpx;
}

// 评测结果
.result-style{
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #B2B2B2;
}

.inforamtion{
	margin-top: 10rpx;
	padding: 10rpx;
	border-radius: 15rpx;
	box-shadow: 0px 4px 20px 0px rgba(0,0,0,0.1);
}
</style>